<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
      <el-form-item label="关键字:" prop="name">
        <el-input
          size="mini"
          v-model="queryParams.name"
          placeholder="请输入关键字"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态:" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="mini">
          <el-option
            v-for="dict in dict.type.enterprise_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="dataList">
      <el-table-column label="序号" type="index" align="center" min-width="5%"/>
      <el-table-column label="企业名称" :show-overflow-tooltip="true" prop="name" key="name" align="center"/>
      <el-table-column label="社会统一信用代码" :show-overflow-tooltip="true" prop="uscc" key="uscc" align="center"/>
      <el-table-column label="通讯地址" :show-overflow-tooltip="true" prop="address" key="address" align="center"/>
      <el-table-column label="法人代表" :show-overflow-tooltip="true" prop="legalRepresentative"
                       key="legalRepresentative" align="center"/>
      <el-table-column label="所属行业" prop="industry" key="industry" align="center"/>
      <el-table-column label="联系电话" prop="mobile" key="mobile" align="center"/>
      <el-table-column label="状态" prop="status" key="status" align="center">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.enterprise_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" prop="createTime" align="center">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" class-name="small-padding fixed-width" align="center">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.status === '1'"
            size="mini"
            type="text"
            @click="changeStatus(scope.row)"
            v-hasPermi="['system:dept:changeShowStatus']"
          >禁用
          </el-button>
          <el-button
            v-if="scope.row.status === '2'"
            size="mini"
            type="text"
            @click="changeStatus(scope.row)"
            v-hasPermi="['system:dept:changeShowStatus']"
          >启用
          </el-button>
          <el-button
            v-if="scope.row.status === '0'"
            size="mini"
            type="text"
            @click="goAudit(scope.row)"
            v-hasPermi="['system:enterprise:audit']"
          >审核
          </el-button>
          <el-button
            size="mini"
            type="text"
            @click="goDetail(scope.row)"
            v-hasPermi="['system:dept:query']"
          >详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <el-dialog title="审核" :visible.sync="auditOpen" width="600px" append-to-body>
      <el-form :model="auditForm" ref="form" label-width="100px">
        <el-form-item label="审核结果:" prop="status">
          <el-radio-group v-model="auditForm.status">
            <el-radio label="1">通过</el-radio>
            <el-radio label="4">驳回</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item v-if="auditForm.status === '4'" label="驳回原因:" prop="failRemark">
          <el-input type="textarea" :rows="3" v-model="auditForm.failRemark" placeholder="请输入驳回原因"
                    clearable/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" size="mini" @click="submitAuditForm">确 定</el-button>
        <el-button size="mini" @click="auditOpen = false">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog title="详情" :visible.sync="detailOpen" width="800px" append-to-body>
      <el-form :model="detail" ref="form" label-width="100px">
        <el-row :gutter="24">
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="企业名称: ">
                {{ detail.name }}
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="社会统一信用代码: ">
                {{ detail.uscc }}
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="通讯地址: ">
                {{ detail.address }}
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="法人代表: ">
                {{ detail.legalRepresentative }}
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="所属行业: ">
                {{ detail.industry }}
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="联系电话: ">
                {{ detail.mobile }}
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="主营业务: ">
                {{ detail.business }}
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="创建时间: ">
                {{ detail.createTime }}
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="状态: ">
                <dict-tag :options="dict.type.enterprise_status" :value="detail.status"/>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="审核人员: ">
                {{ detail.auditUserName }}
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="审核时间: ">
                {{ detail.createTime }}
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12" v-if="detail.status === '4'">
            <div class="grid-content bg-purple">
              <el-form-item label="驳回原因: ">
                {{ detail.failRemark }}
              </el-form-item>
            </div>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
import { pageList, changeStatus, getInfo, audit } from '@/api/triones/enterprise'
export default {
  name: "index",
  dicts: ['enterprise_status'],
  data() {
    return {
      loading: false,
      showSearch: true,
      total: 0,
      dataList: [],
      title: "",
      auditOpen: false,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: undefined,
      },
      auditForm: {
        id: undefined,
        status: undefined,
        failRemark: undefined
      },
      detailOpen: false,
      detail: {}
    }
  },
  created() {
    this.getList();
  },
  methods: {
    // 获取表格数据
    getList() {
      this.loading = true;
      pageList(this.queryParams).then(response => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    changeStatus(row) {
      let text = row.status === '1' ? "禁用" : "启用";
      let value = row.status === '1' ? "2" : "1";
      this.$modal.confirm('确认要"' + text + '""' + '该企业吗？').then(function () {
        return changeStatus(row.id, value);
      }).then(() => {
        this.$modal.msgSuccess(text + "成功");
        this.getList();
      })
    },
    goAudit(row) {
      this.auditForm = {
        id: row.id,
        status: undefined,
        failRemark: undefined
      }
      this.auditOpen = true;
    },
    goDetail(row) {
      const id = row.id;
      getInfo(id).then(response => {
        this.detail = response.data;
        this.detailOpen = true;
      })
    },
    submitAuditForm() {
      audit(this.auditForm).then(response => {
        this.$modal.msgSuccess("操作成功");
        this.auditOpen = false;
        this.getList();
      })
    }
  }
}
</script>
<style scoped lang="scss">

</style>
